class Solution {

    static sortColors(nums) {
        let i = 0
        let less_than = 0
        let great_than = nums.length

        while (i < great_than) {
            if (nums[i] === 0) {
                Solution._exchange(nums, i, less_than)
                less_than += 1
                i += 1
            }else if (nums[i] === 1) {
                i += 1
            }else if (nums[i] === 2) {
                great_than -= 1
                Solution._exchange(nums, i, great_than)
            }
        }
    }

    static _exchange(nums, i, j) {
        let temp = nums[i]
        nums[i] = nums[j]
        nums[j] = temp
    }
}


let nums1 = [2, 0, 1, 2, 1, 0]
let nums2 = [2, 0, 1]

Solution.sortColors(nums1)
Solution.sortColors(nums2)

console.log(nums1)
console.log(nums2)
